<?php  
	session_start();
	
	/* Used for communication with the database */
	require_once("classes/Mail.class.php");
	include("classes/database.class.php");
	include("includes/define.php");
	$bd = new Database(MYSQL_DB_HOST,MYSQL_DB_LOGIN,MYSQL_DB_PASSWORD,MYSQL_DB_NAME);	

	date_default_timezone_set('Europe/Paris');
	$today = date("Y")."-".date("m")."-".date("d");
	
	/* If someone try to go directly to this URL, redirect to index */
	if(!isset($_SESSION['participantId']))
	{
		header("Location: http://".$_SERVER['SERVER_NAME']);
	}
	/* If the participant want to come back to his page */
	elseif(isset($_POST['back']))
	{
		header("Location: http://".$_SERVER['SERVER_NAME']."/participant.php");
	}
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
<title> Panneau étudiant </title>
</head>

<body>

	<h1> <?php echo $_SESSION['participantId']." - Données"; ?> </h1>

	<form method="post" action="participant.php">
		<input type="submit" name="back" value="Retour"/>
	</form>
	
	<?php
		$adjectifs;
		$adjectifs['11']='Intéréssé'; $adjectifs['12']='Intéressée';
		$adjectifs['21']='Angoissé'; $adjectifs['22']='Angoissée';
		$adjectifs['31']='Excité'; $adjectifs['32']='Excitée';
		$adjectifs['41']='Fâché'; $adjectifs['42']='Fâchée';
		$adjectifs['51']='Fort'; $adjectifs['52']='Forte';
		$adjectifs['61']='Coupable'; $adjectifs['62']='Coupable';
		$adjectifs['71']='Effrayé'; $adjectifs['72']='Effrayée';
		$adjectifs['81']='Hostile'; $adjectifs['82']='Hostile';
		$adjectifs['91']='Enthousiaste'; $adjectifs['92']='Enthousiaste';
		$adjectifs['101']='Fier'; $adjectifs['102']='Fiere';
		$adjectifs['111']='Irrité'; $adjectifs['112']='Irritée';
		$adjectifs['121']='Alerte'; $adjectifs['122']='Alerte';
		$adjectifs['131']='Honteux'; $adjectifs['132']='Honteuse';
		$adjectifs['141']='Inspiré'; $adjectifs['142']='Inspirée';
		$adjectifs['151']='Nerveux'; $adjectifs['152']='Nerveuse';
		$adjectifs['161']='Déterminé'; $adjectifs['162']='Déterminée';
		$adjectifs['171']='Attentif'; $adjectifs['172']='Attentive';
		$adjectifs['181']='Agité'; $adjectifs['182']='Agitée';
		$adjectifs['191']='Actif'; $adjectifs['192']='Active';
		$adjectifs['201']='Craintif'; $adjectifs['202']='Craintive';
	
		$DATABASE_participantSessions = $bd->query("SELECT * FROM participantsSessions WHERE participantId = '".$_SESSION['participantId']."';");

		while($DATABASE_participantSession = mysql_fetch_assoc($DATABASE_participantSessions))
		{
			$DATABASE_Session = $bd->query("SELECT * FROM sessions WHERE sessionId = '".$DATABASE_participantSession['sessionId']."';");
			$DATABASE_Session = mysql_fetch_assoc($DATABASE_Session);
			$DATABASE_participantStudy = $bd->query("SELECT endDate FROM studies WHERE studyId = '".$DATABASE_Session['studyId']."';");
			$DATABASE_participantStudy = mysql_fetch_assoc($DATABASE_participantStudy);
				
			if($DATABASE_participantStudy['endDate'] != NULL)
			{
				$DATABASE_Session = $bd->query("SELECT * FROM sessions WHERE sessionId = '".$DATABASE_participantSession['sessionId']."';");
				$DATABASE_Session = mysql_fetch_assoc($DATABASE_Session);
				$DATABASE_Panas = $bd->query("SELECT * FROM panasAnswers WHERE participantSessionId = '".$DATABASE_participantSession['participantSessionId']."';");
				if(mysql_num_rows($DATABASE_Panas) != 0)
				{
					$DATABASE_Panas = mysql_fetch_array($DATABASE_Panas);
					
					echo "<br/>
						<hr/>
						<p>Session du ".$DATABASE_Session['date']." </p>
						<table>
								<thead>
									<tr>
										<td> </td>
										<td>Très peu ou pas du tout</td>
										<td>Peu</td>
										<td>Modérément</td>
										<td>Beaucoup</td>
										<td>Énormément</td>
									</tr>
								</thead>
								<tfoot>
									<tr>
										<td> </td>
										<td>Très peu ou pas du tout</td>
										<td>Peu</td>
										<td>Modérément</td>
										<td>Beaucoup</td>
										<td>Énormément</td>
									</tr>
								</tfoot>
								<tbody>";
								
								for($i=1; $i<=20; $i++)
								{
									echo "<tr> 
											<td class='left'>".$i.". ".$adjectifs[($i*10)+$_SESSION['gender']]."</td>
											<td>"; if($DATABASE_Panas[$i+1]==1){echo "X";} echo "</td>
											<td>"; if($DATABASE_Panas[$i+1]==2){echo "X";} echo "</td>
											<td>"; if($DATABASE_Panas[$i+1]==3){echo "X";} echo "</td>
											<td>"; if($DATABASE_Panas[$i+1]==4){echo "X";} echo "</td>
											<td>"; if($DATABASE_Panas[$i+1]==5){echo "X";} echo "</td>";
									}
									echo "</tr>
										</tbody>
										</table>";
					
					$DATABASE_Colors = $bd->query("SELECT * FROM colorAnswers WHERE participantSessionId = '".$DATABASE_participantSession['participantSessionId']."';");
					if(mysql_num_rows($DATABASE_Colors) != 0)
					{
						$DATABASE_Shapes = $bd->query("SELECT * FROM shapes;");
	
						echo " <br/><br/>
							<table>
								<thead>
									<tr>
										<td>Paire de couleur</td>
										<td>Forme</td>
										<td>Choix</td>
										<td>Temps</td>
									</tr>
								</thead>
								<tfoot>
									<tr>
										<td>Paire de couleur</td>
										<td>Forme</td>
										<td>Choix</td>
										<td>Temps</td>
									</tr>
								</tfoot>
								<tbody>";
								
								while($DATABASE_Color = mysql_fetch_array($DATABASE_Colors))
								{
									echo "<tr> 
											<td class='left'>".$DATABASE_Color['leftColorName']." - ".$DATABASE_Color['rightColorName']."</td>
											<td>".$DATABASE_Color['shapeName']."</td>
											<td>".$DATABASE_Color['chosenColorName']."</td>
											<td>".$DATABASE_Color['time']."</td>";
								}
							echo "</tr>
								</tbody>
								</table>";
					}
				}
			}
		}
		
		$bd->close();
	?>
	
</body>
</html>